package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * 截取集合
 */
public class SubListDemo {
    public static void main(String[] args) {
        /**
        List提供了获取子集的操作：
         List subList(int start,int end):含头不含尾
         */
        List<Integer>list=new ArrayList<>();
        for (int i = 0; i <10 ; i++) {
            list.add(i*10);
        }
        System.out.println("list = " + list);

        List<Integer>subList=list.subList(3,8);//获取下标3-7的子集
        System.out.println("subList = " + subList);
        System.out.println("********************************");

        //将子集扩大10倍
        for (int i = 0; i <subList.size() ; i++) {
            subList.set(i,subList.get(i)*10);
        }
        System.out.println("subList = " + subList);
        //对子集的操作就是对原集合的相应的元素操作
        System.out.println("list = " + list);
        System.out.println("-----------------------------");

        list.set(3,1000);
        System.out.println("list = " + list);
        //修改原集合数组后，子集也会跟着变化
        System.out.println("subList = " + subList);
        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

        list.remove(0);
        System.out.println("list = " + list);
        //原集合长度修改后，子集将不能进行任何操作，否则发生异常，但可以重新获取子集
        //System.out.println("subList = " + subList);


    }
}
